public class TestPolymorphism {
    public static void main(String[] args) {
        Car[] cars = new Car[5];
        cars[0] = new Car("CAR0000001","Chevrolet",10,150000.00);
        cars[1] = new ElectricCar("ElE0000002","Audi",15,220000.00,60);
        cars[2] = new PetrolCar("PET0000003","BMW",15,200000.00,55.0);
        cars[3] = new Car("CAR0000004","Ford",15,200000.00);
        cars[4] = new Car("CAR0000005","Honda",15,200000.00);
        // Dynamic binding and type casting
        for(Car car : cars) {//对数组车每一个进行遍历
            // Print the description of each car item
            System.out.println(car.getDescription());
            // If it's an ElectricCar, call its specific method to charge the battery
            if (car instanceof ElectricCar) {
                ((ElectricCar) car).chargeBattery();
            }
            // If it's a PetrolCar, call its specific method to fill the tank
            if(car instanceof PetrolCar) {

                ((PetrolCar) car).filltankSize();
            }
        }

    }
}
